<template>
  <div class="container">
    <div class="ibox-content no-border no-padding-bottom">
      <!--搜索栏-->
      <el-col class="toolbar">
        <el-form :inline="true" size="mini" :model="filterForm" ref="filterForm" label-width="100px">
          <el-form-item label="id">
            <el-input v-model="filterForm.id" placeholder="id"></el-input>
          </el-form-item>
          <el-form-item label="用户id">
            <el-input v-model="filterForm.uid" placeholder="用户id"></el-input>
          </el-form-item>
          <el-form-item label="用户手机号">
            <el-input v-model="filterForm.user_phone" placeholder="用户手机号"></el-input>
          </el-form-item>
          <el-form-item label="客户端">
            <el-select style="width: 178px" v-model="filterForm.client" placeholder="客户端">
              <el-option label="全部" value=""></el-option>
              <el-option :label="item" :value="key" :key="index"
                         v-for="(item,key,index) in selectOptions.client"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="渠道">
            <el-input v-model="filterForm.channel_name" placeholder="模糊匹配渠道名称"></el-input>
          </el-form-item>
          <el-form-item label="产品">
            <el-input v-model="filterForm.app_name" placeholder="模糊匹配产品名称"></el-input>
          </el-form-item>
          <el-form-item label="减息卡金额">
            <el-input v-model="filterForm.card_amount" placeholder="减息卡金额"></el-input>
          </el-form-item>
          <el-form-item label="贷款次数">
            <el-input v-model="filterForm.loan_number" placeholder="贷款次数"></el-input>
          </el-form-item>
          <el-form-item label="状态">
            <el-select style="width: 178px" v-model="filterForm.status" placeholder="状态">
              <el-option label="全部" value=""></el-option>
              <el-option :label="item" :value="key" :key="index"
                         v-for="(item,key,index) in selectOptions.use_status"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="获取时间">
            <el-date-picker
                    v-model="chooseTime"
                    type="daterange"
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    value-format="yyyy-MM-dd"
                    @change="chooseDate"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button @click="filterClick" type="primary">查询</el-button>
            <el-button @click="resetFilterForm('filterForm')">重置</el-button>
          </el-form-item>
          <!--          <div class="hr-line-dashed"></div>-->
          <!--          <br/>-->
          <!--          <el-form-item v-show="false">-->
          <!--            <el-button type="primary" plain>添加用户减息卡</el-button>-->
          <!--          </el-form-item>-->
        </el-form>
      </el-col>
    </div>
    <div class="ibox-content">
      <!--表格-->
      <el-table
              ref="multipleTable"
              :data="arrList"
              size="medium"
              border
              highlight-current-row
              tooltip-effect="dark"
              style="width: 100%"
              :max-height="500"
              v-loading="tableLoading"
      >
        <el-table-column prop="id" label="ID" width="80"></el-table-column>
        <el-table-column prop="uid" label="用户ID" width="80"></el-table-column>
        <el-table-column prop="user_phone" label="用户手机号"></el-table-column>
        <el-table-column prop="client" label="客户端"></el-table-column>
        <el-table-column prop="channel_name" label="渠道"></el-table-column>
        <el-table-column prop="app_name" label="产品"></el-table-column>
        <el-table-column prop="card_amount" label="减息卡金额">
          <template slot-scope="scope">
            <span>￥{{scope.row.card_amount}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="loan_number" label="贷款次数"></el-table-column>
        <el-table-column prop="created_at" label="获取时间" width="170"></el-table-column>
        <el-table-column prop="status" label="状态">
          <template slot-scope="scope">
            <span class="green" v-show="scope.row.status==1">未使用</span>
            <span class="" v-show="scope.row.status==10">提现中</span>
            <span class="warning" v-show="scope.row.status==20">已使用</span>
            <span class="red" v-show="scope.row.status==30">已失效</span>
          </template>
        </el-table-column>
      </el-table>
      <!--分页工具条-->
      <div v-show="arrList.length>0" style="margin-top: 18px;text-align: center">
        <el-pagination
                @current-change="handleCurrentChange"
                :current-page="pageInfo.currPage"
                :page-sizes="[20]"
                :page-size="pageInfo.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="pageInfo.totalCount">
        </el-pagination>
      </div>

    </div>

  </div>
</template>

<script>
  import {userRateCard, userOptions} from "../../api/user";

  export default {
    name: "UserRateCard",
    data() {
      return {
        arrList: [],
        pageInfo: {
          totalPage: 0,// 总页数
          totalCount: 0,// 总条数
          pageSize: 0,// 每页条数
          currPage: 1// 当前页
        },
        filterForm: {},
        tableLoading: false,
        tableSelectData: [],
        selectOptions: {},
        chooseTime: ''
      }
    },
    created() {
      this.getSelectOptions();
      this.initData();
    },
    methods: {
      initData() {
        this.tableLoading = true;
        userRateCard({
          page: this.pageInfo.currPage,
          ...this.filterForm
        }).then(res => {
          this.tableLoading = false;
          const {listData, page} = res.data;
          this.arrList = listData;
          this.pageInfo = page
        }).catch(() => {
          this.tableLoading = false;
        })
      },
      getSelectOptions() {
        userOptions({}).then(res => {
          this.selectOptions = res.data;
        }).catch(() => {

        })
      },
      //分页
      handleCurrentChange(val) {
        // console.log(val);
        this.pageInfo.currPage = val;
        this.initData();
      },
      filterClick() {
        this.pageInfo.currPage = 1;
        this.initData();
      },
      //重置
      resetFilterForm(form) {
        this.$refs[form].resetFields();
        this.filterForm = {};
        this.chooseTime = '';
        this.pageInfo.currPage = 1;
        this.initData();
      },
      //选择时间
      chooseDate(val) {
        this.filterForm.start_date = val[0];
        this.filterForm.end_date = val[1];
      }
    }
  }
</script>

<style scoped lang="scss">

</style>
